﻿CREATE PROCEDURE [dbo].[ProgramType_InsertUpdate]

	@id					BIGINT,

	@name				VARCHAR (0060), 

	@description		VARCHAR (0999),


	@code				VARCHAR (0003),

	@enabled			BIT,

	@modifiedId			VARCHAR (0060)

AS

	BEGIN 

		MERGE ProgramType

			USING (SELECT @id) AS Source (Id)

				ON ProgramType.Id = Source.Id

			WHEN MATCHED THEN 

				UPDATE SET 

					Name = @name,

					Description = @description,

					Code = @code,

					Enabled = @enabled,

					ModifiedId = @modifiedId,

					ModifiedDateTime = GETDATE ()

			WHEN NOT MATCHED THEN 

				INSERT (Name, Description, Code, Enabled, CreateId, CreateDateTime, ModifiedId, ModifiedDateTime) 

					VALUES (@name, @description, @code, @enabled, @modifiedId, GETDATE (), @modifiedId, GETDATE())

		; -- MERGE ( END )


	END

	